#ifndef PLAYER_MSQ_Q_H
#define PLAYER_MSQ_Q_H

#include <errno.h>
#include <pthread.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <time.h>
#include <sys/time.h>
#include <sys/times.h>

#include "common.h"

#define MSG_Q_NAME_LEN			16
#define MSG_Q_MAX_DATA_SIZE	(4096+512)
#define MSG_Q_MAX_MSGS			4095

typedef struct msg_q_t
{
	struct msg_q_t 	*previous;
	struct msg_q_t 	*next;
	pthread_cond_t 	read_cond;
	pthread_cond_t 	write_cond;
	pthread_mutex_t mutex;
	BYTE			*read;
	BYTE			*write;
	BYTE			*end;
	SIZE_T			message_size;
	SIZE_T			z_max_size;
	UINT16			ui2_msg_count;
	INT16			i2_refcount;
	CHAR			s_name[MSG_Q_NAME_LEN + 1];
	BYTE			start[1];
}MSG_Q_T;

typedef enum
{
	MSG_Q_OPTION_WAIT = 1,
	MSG_Q_OPTION_NOWAIT
}MSG_Q_OPTION_T;

extern "C"{

//public
INT32	msg_q_create(HANDLE_T*	ph_msg_hdl,
					const CHAR*	ps_name,
					SIZE_T		z_msg_zise,
					INT16		ui2_max_msg_count);
INT32	msg_q_delete(HANDLE_T	h_msg_hdl);
INT32	msg_q_send(HANDLE_T		h_msg_hdl,
					const VOID *pv_msg,
					SIZE_T		z_size,
					UINT8		ui1_pri);
INT32	msg_q_receive(UINT16	*pui2_index,
					   VOID		*pv_msg,
					   SIZE_T		*pz_size,
					   HANDLE_T	*ph_msg_q_hdl_list,
					   UINT16		ui2_msg_q_hdl_count,
					   MSG_Q_OPTION_T	e_option);
//private
MSG_Q_T *msg_q_find_obj(const CHAR *ps_name);
void 	msg_q_list_add(MSG_Q_T *pt_msg_q);
void 	msg_q_list_remove(MSG_Q_T 	*pt_msg_q);
}
#endif